package com.hzit.listener;

import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;

/**
 * 1、监听请求对象及属性值的变化
 */
@WebListener
// ServletRequestListener: 对请求对象进行监听
// ServletRequestAttributeListener: 对请求对象的属性进行监听
public class MyRequestListener implements ServletRequestListener, ServletRequestAttributeListener {
	//1. 请求对象初始化时触发
	@Override
	public void requestInitialized(ServletRequestEvent sre) {
		System.out.println("请求对象被创建：MyRequestListener--->requestInitialized()");
	}
	//2. 请求对象被销毁时触发
	@Override
	public void requestDestroyed(ServletRequestEvent sre) {
		System.out.println("请求对象被销毁：MyRequestListener--->requestDestroyed()");
	}
	//3. 在请求对象中添加属性时触发
	@Override
	public void attributeAdded(ServletRequestAttributeEvent srae) {
		System.out.println("请求对象属性被添加：MyRequestListener--->attributeAdded()");
	}

	@Override
	public void attributeRemoved(ServletRequestAttributeEvent srae) {
		System.out.println("请求对象属性被移除：MyRequestListener--->attributeRemoved()");
	}

	@Override
	public void attributeReplaced(ServletRequestAttributeEvent srae) {

	}


}
